home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / WASTE Object Handlers 1.2.6.sit / WASTE Object Handlers 1.2.6 / Handler Source / WE_PICT_Handler.c < prev    next >
Text File  |  1997-07-21  |  3KB  |  130 lines

  1. // PICT Object Handler for the WASTE Text Engine
  2. // by Michael F. Kamprath, kamprath@kagi.com
  3. // maintenance by John C. Daub, hsoi@eden.com
  4. //
  5. // v1.0, 12 March 1995
  6. // v1.1, 5 June 1995,     Added InstallPICTObject() to install the PICT handler
  7. //                        by itself.
  8. // v1.2, 28 March 1996. Minor updates.  Added precompiler directives, WASTE 1.2a5 compatability
  9. //
  10. // v1.2.2, 16 July 1996. Added compatability with WASTE 1.2 and CW9
  11. //                         Restructured installation routines
  12.  
  13. #ifndef _WASTE_
  14. #include "WASTE.h"
  15. #endif
  16.  
  17. #include "WE_PICT_Handler.h"
  18.  
  19. #ifndef _WASTEOBJECTS_
  20. #include "WASTE_Objects.h"
  21. #endif
  22.  
  23. #ifndef topLeft
  24. #define topLeft(r)    (((Point *) &(r))[0])
  25. #endif
  26. #ifndef botRight
  27. #define botRight(r)    (((Point *) &(r))[1])
  28. #endif
  29.  
  30. #ifndef true
  31. #define true 1
  32. #endif
  33.  
  34. #ifndef false
  35. #define false 0
  36. #endif
  37.  
  38. //
  39. // InstallPICTObject()
  40. //        Installs the PICT handler into WASTE.
  41. //
  42. OSErr    InstallPICTObject( WEReference theWE )
  43. {
  44. OSErr    iErr;
  45.  
  46. #ifdef __cplusplus
  47.     static WENewObjectUPP            newPICTUPP = NewWENewObjectProc(HandleNewPicture);
  48.     static WEDisposeObjectUPP        disposePICTUPP = NewWEDisposeObjectProc(HandleDisposePicture);
  49.     static WEDrawObjectUPP            drawPICTUPP = NewWEDrawObjectProc(HandleDrawPicture);
  50. #else
  51.     static WENewObjectUPP            newPICTUPP = NULL;
  52.     static WEDisposeObjectUPP        disposePICTUPP = NULL;
  53.     static WEDrawObjectUPP            drawPICTUPP = NULL;
  54.  
  55.  
  56.     if ( newPICTUPP == NULL )
  57.         newPICTUPP = NewWENewObjectProc(HandleNewPicture);
  58.     if ( disposePICTUPP == NULL )
  59.         disposePICTUPP = NewWEDisposeObjectProc(HandleDisposePicture);
  60.     if ( drawPICTUPP == NULL )
  61.         drawPICTUPP = NewWEDrawObjectProc(HandleDrawPicture);
  62. #endif
  63.  
  64.     if ( newPICTUPP != NULL )
  65.         iErr = WEInstallObjectHandler(kTypePicture, weNewHandler, (UniversalProcPtr)newPICTUPP, theWE);
  66.     else
  67.         iErr = weUnknownObjectTypeErr;
  68.     if (iErr) return(iErr);
  69.     
  70.     if ( disposePICTUPP != NULL )
  71.         iErr = WEInstallObjectHandler(kTypePicture, weDisposeHandler, (UniversalProcPtr)disposePICTUPP, theWE);
  72.     else
  73.         iErr = weUnknownObjectTypeErr;
  74.     if (iErr) return(iErr);
  75.     
  76.     if ( drawPICTUPP != NULL )
  77.         iErr = WEInstallObjectHandler(kTypePicture, weDrawHandler, (UniversalProcPtr)drawPICTUPP, theWE);
  78.     else
  79.         iErr = weUnknownObjectTypeErr;
  80.     if (iErr) return(iErr);
  81.     
  82.     return(noErr);
  83. }
  84.  
  85. //
  86. // New Object Handler for PICTs
  87. //
  88. pascal OSErr    HandleNewPicture(Point *defaultObjectSize,WEObjectReference objectRef)
  89. {
  90. PicHandle    thePic;
  91. Rect        theFrame;
  92.  
  93.     thePic = (PicHandle)WEGetObjectDataHandle(objectRef);
  94.     
  95.     theFrame = (*thePic)->picFrame;
  96.     
  97.     OffsetRect(&theFrame, -theFrame.left, -theFrame.top);
  98.     
  99.     *defaultObjectSize = botRight(theFrame);
  100.         
  101.     return(noErr);
  102. }
  103.  
  104. //
  105. // Dispose Object Handler for PICTS
  106. //
  107. pascal OSErr    HandleDisposePicture(WEObjectReference objectRef )
  108. {
  109. PicHandle    thePic;
  110.  
  111.     thePic = (PicHandle)WEGetObjectDataHandle(objectRef);
  112.     
  113.     if (thePic)
  114.         KillPicture(thePic);
  115.  
  116.     return(MemError());
  117. }
  118. //
  119. // Draw Object Handler for PICTs
  120. //
  121. pascal OSErr    HandleDrawPicture (Rect *destRect, WEObjectReference objectRef )
  122. {
  123. PicHandle    thePic;
  124.     
  125.     thePic = (PicHandle)WEGetObjectDataHandle(objectRef);
  126.  
  127.     DrawPicture(thePic, destRect);
  128.             
  129.     return( noErr );
  130. }